package com.newcapce.thread;

public class ThreadDemo1 {
    public static void main(String[] args) {
        //Runnable
        //Thread
//        Thread thread = new Thread(){
//            @Override
//            public void run() {
//                for(int i = 1; i <= 100; i++){
//                    System.out.println(i);
//                    try {
//                        Thread.sleep(100);
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//        };

        Thread thread1 = new MyThread();
        Thread thread2 = new MyThread();
        //此处启动线程
        thread1.start();
        thread2.start();


        System.out.println("我是主线程"+Thread.currentThread().getName());
    }
}

class MyThread extends Thread{
    @Override
    public void run() {
        for(int i = 1; i <= 100; i++){
            System.out.println(i+":"+Thread.currentThread().getName());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
